﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Openfree.Framework.DataAccess;
using System.Text;

public partial class Controls_Activity_ValidateUser : BaseUserControl
{
    public EventHandler OnValidateUser;

    UserAccess user;
    protected void Page_Load(object sender, EventArgs e)
    {
        tbLoginname.Attributes.Add("onkeypress", "Openfree.prototype.EnterSubmit('" + btnModalPopupOK.ClientID + "',event);");
        tbPassword.Attributes.Add("onkeypress", "Openfree.prototype.EnterSubmit('" + btnModalPopupOK.ClientID + "',event);");
        if (btnModalPopupOK.ClientID.Equals(Request["__EVENTTARGET"]))
        {
            btnModalPopupOK_Click(sender, e);
        }
    }

    public void ShowModalPopup()
    {
        literalModalPopup.Text = "请输入用户名和密码";
        tbPassword.Text = "";
        modalPopup.Show();
    }

    public string GetUserID()
    {
        UserAccess user = new UserAccess(base.Connection);
        return user.GetUserIDByLoginName(tbLoginname.Text.Trim());
    }

    protected void btnModalPopupOK_Click(object sender, EventArgs e)
    {
        if (OnValidateUser != null)
        {
            UserAccess user = new UserAccess(base.Connection);
            int result = user.ValidateUser(tbLoginname.Text.Trim(), 
                tbPassword.Text, 
                ConfigManager.PasswordKey);


            UserSelectEventArgs ev = new UserSelectEventArgs();
            ev.SelectDataSet = SessionManager.DataSet;
            
            OnValidateUser(result, ev);
        } 
    }
}
